(function() {
  var format, format_G;

  format = function(size) {
    if (size >= 1024 * 1024 * 1024) {
      return (size / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
    } else if (1024 * 1024 * 1024 > size && size >= 1024 * 1024) {
      return (size / (1024 * 1024)).toFixed(2) + ' MB';
    } else {
      return (size / 1024).toFixed(2) + ' KB';
    }
  };

  format_G = function(size) {
    if (size >= 1) {
      return size.toFixed(2) + ' GB';
    } else if (1 > size && size >= 1 / 1024) {
      return (size * 1024).toFixed(2) + ' MB';
    } else {
      return (size * 1024 * 1024).toFixed(2) + ' KB';
    }
  };

  $(function() {
    var format_total, fs_size, fssize_chart, index, item, option, total, _i, _j, _len, _len1;
    fs_size = JSON.parse(window.fs_size);
    fssize_chart = echarts.init(document.getElementById('fs_size'));
    total = 0;
    for (_i = 0, _len = fs_size.length; _i < _len; _i++) {
      item = fs_size[_i];
      total += item.size;
    }
    format_total = format(total);
    option = {
      title: {
        text: '文件系统使用情况',
        subtext: '磁盘总容量：' + format_total,
        subtextStyle: {
          color: 'blue'
        },
        x: 'center',
        padding: [0, 0]
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        },
        formatter: function(params) {
          var free, used;
          used = format_G(params[0].value);
          free = format_G(params[1].value);
          return '挂载点：' + params[0].name + '<br/>' + params[1].seriesName + '：' + free + '<br/>' + params[0].seriesName + '：' + used;
        }
      },
      legend: {
        orient: 'vertical',
        x: 'left',
        data: ['剩余空间', '已用空间']
      },
      grid: {
        left: '3%',
        right: '15%',
        bottom: '3%',
        top: '25%',
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          name: '挂载点',
          data: []
        }
      ],
      yAxis: [
        {
          type: 'value',
          name: 'GB'
        }
      ],
      series: [
        {
          name: '已用空间',
          type: 'bar',
          stack: '文件系统',
          barCategoryGap: '30%',
          barWidth: '30px',
          itemStyle: {
            normal: {
              color: '#AE0000'
            }
          },
          data: []
        }, {
          name: '剩余空间',
          type: 'bar',
          stack: '文件系统',
          label: {
            normal: {
              show: true,
              position: 'top',
              formatter: function(params) {
                var total_size;
                if (!fs_size[params.dataIndex]) {
                  return "未知";
                }
                total_size = format(fs_size[params.dataIndex].size);
                return total_size;
              }
            }
          },
          itemStyle: {
            normal: {
              color: '#00A600'
            }
          },
          data: []
        }
      ]
    };
    for (index = _j = 0, _len1 = fs_size.length; _j < _len1; index = ++_j) {
      item = fs_size[index];
      option.xAxis[0].data[index] = item.mount;
      option.series[0].data[index] = item.used / (1024 * 1024 * 1024);
      option.series[1].data[index] = (item.size - item.used) / (1024 * 1024 * 1024);
    }
    return fssize_chart.setOption(option);
  });

}).call(this);
